import { ConfigInterceptor } from './config-interceptor';
import { Http, HttpModule, Headers, RequestOptions } from '@angular/http';
import { ValueService } from './services/value.service';
import { DataService } from './services/data.service';
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { RedPacketComponent } from './red-packet/red-packet.component';

import { InterceptorService } from 'ng2-interceptors';
import { XHRBackend} from '@angular/http';
import { SharedGoodsComponent } from './shared-goods/shared-goods.component';
import { ErrorComponent } from './error/error.component';
export function interceptorFactory(xhrBackend: XHRBackend, requestOptions: RequestOptions, ConfigInterceptor:ConfigInterceptor){ // Add it here
  let service = new InterceptorService(xhrBackend, requestOptions);
  service.addInterceptor(ConfigInterceptor); // Add it here
  return service;
}

@NgModule({
  declarations: [
    AppComponent,
    RedPacketComponent,
    SharedGoodsComponent,
    ErrorComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    FormsModule, // 模板式表单
    ReactiveFormsModule, // 响应式表单
    HttpModule
  ],
  providers: [
    DataService,
    ValueService,
    ConfigInterceptor,
    {
      provide: InterceptorService,
      useFactory: interceptorFactory,
      deps: [XHRBackend, RequestOptions, ConfigInterceptor]
    }
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }
